package com.ruoyi.web.controller.mocha;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mocha.domain.MochaSymbol;
import com.ruoyi.mocha.service.IMochaSymbolService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 交易对信息Controller
 * 
 * @author ruoyi
 * @date 2021-04-23
 */
@Controller
@RequestMapping("/system/symbol")
public class MochaSymbolController extends BaseController
{
    private String prefix = "system/symbol";

    @Autowired
    private IMochaSymbolService mochaSymbolService;

    @RequiresPermissions("system:symbol:view")
    @GetMapping()
    public String symbol()
    {
        return prefix + "/symbol";
    }

    /**
     * 查询交易对信息列表
     */
    @RequiresPermissions("system:symbol:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MochaSymbol mochaSymbol)
    {
        startPage();
        List<MochaSymbol> list = mochaSymbolService.selectMochaSymbolList(mochaSymbol);
        return getDataTable(list);
    }

    /**
     * 导出交易对信息列表
     */
    @RequiresPermissions("system:symbol:export")
    @Log(title = "交易对信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MochaSymbol mochaSymbol)
    {
        List<MochaSymbol> list = mochaSymbolService.selectMochaSymbolList(mochaSymbol);
        ExcelUtil<MochaSymbol> util = new ExcelUtil<MochaSymbol>(MochaSymbol.class);
        return util.exportExcel(list, "交易对信息数据");
    }

    /**
     * 新增交易对信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交易对信息
     */
    @RequiresPermissions("system:symbol:add")
    @Log(title = "交易对信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MochaSymbol mochaSymbol)
    {
        return toAjax(mochaSymbolService.insertMochaSymbol(mochaSymbol));
    }

    /**
     * 修改交易对信息
     */
    @GetMapping("/edit/{symbolId}")
    public String edit(@PathVariable("symbolId") Long symbolId, ModelMap mmap)
    {
        MochaSymbol mochaSymbol = mochaSymbolService.selectMochaSymbolById(symbolId);
        mmap.put("mochaSymbol", mochaSymbol);
        return prefix + "/edit";
    }

    /**
     * 修改保存交易对信息
     */
    @RequiresPermissions("system:symbol:edit")
    @Log(title = "交易对信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MochaSymbol mochaSymbol)
    {
        return toAjax(mochaSymbolService.updateMochaSymbol(mochaSymbol));
    }

    /**
     * 删除交易对信息
     */
    @RequiresPermissions("system:symbol:remove")
    @Log(title = "交易对信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mochaSymbolService.deleteMochaSymbolByIds(ids));
    }
}
